#pragma GCC optimize(2)
#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
#include <bitset>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pii;
const int N=2e5+10;

pii a[N];
ll sum[N];
ll ans[N];
int main()
{
	IOS;
	int t;
	cin>>t;
	while(t--)
	{
		map<int,int> mp;
		int n;
		cin>>n;
		for(int i=1;i<=n;i++) cin>>a[i].first,a[i].second=i;
		
		sort(a+1,a+1+n);
		
		for(int i=1;i<=n;i++)
		{
			sum[i]=sum[i-1]+a[i].first;
		}
		ll last=0;
		for(int i=1;i<=n;i++)
		{
			int id=a[i].second;
			if(mp[a[i].first])
			{
				ans[id]=last;
				continue;
			}
			mp[a[i].first]++;
			last=0;
			ll suf=sum[n]-sum[i]-a[i].first*(n-i)+(n-i);
			ll pre=a[i].first*(i-1)-sum[i-1]+(i-1);
			ans[id]=suf+pre+1;
			last=ans[id];
		}
		for(int i=1;i<=n;i++) cout<<ans[i]<<' ';
		cout<<endl;
	}

	return 0;
}

